home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 11 / Cream of the Crop 11-2.iso / os2 / os2cl015.zip / pmpp.doc < prev    next >
Text File  |  1995-11-24  |  12KB  |  316 lines

  1.  
  2.  
  3.  
  4.  
  5.     PM++
  6.     
  7.     Version 0.08
  8.     11-26-1994
  9.  
  10.     Version 0.15
  11.     10-03-1995
  12.     
  13.     Giovanni Iachello
  14.  
  15.     A freeware class library for the Presentation Manager API
  16.     
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.     1. Introduction
  32.     
  33.     This manual page is written in my terrible english, but considering that
  34. "Real Programmers Don't Read Manuals", I feel it's enough. 
  35. PM++ is a freeware class library that encapsulates some of the OS/2 
  36. Presentation Manager API calls. I developed it using the emx distribution
  37. of the GNU C++ Compiler with the general idea of writing some support 
  38. programs for programmers who want to write presentation manager applications
  39. without buying expensive compilers. It is obvious that for professional
  40. applications some tools distributed with the commercial packages are needed
  41. (particulary the help compiler, CASE tools etc etc), but for normal, 
  42. small, programs emx should be sufficient. 
  43.  
  44. With this idea the first step was finding out what is missing to emx's PM 
  45. support. This led me to a class library to encapsulate the PM API. 
  46.  
  47. My library is similar, in the general design, to Paul DiLascia's
  48. Windows++ library: it's simple, small, and adds only a very thin layer 
  49. between OS/2 and C++ programs to PM applications, to the benefit of 
  50. effincency and size. It is compiled in a 32-bit DLL, to save disk space
  51. on multiple, or different, programs that use it. 
  52.  
  53.  
  54.  
  55.     2. Support Classes
  56.     
  57.     There is a certain number of support classes, which make it easy
  58. to deal with some of the most used PM data types and structures.
  59. For example there is a PMPoint class which derives from the POINTL
  60. structure and overloads the +, -, * operators, with their obvious
  61. functions.  It is possible to pass a PMPoint structure to an PM API
  62. function which expects a PPOINTL pointer, and there are inline functions
  63. to query the single members of the internal POINTL structures (x and y).
  64. There is also a PMRect class which is very similar to the PMPoint class,
  65. except for the fact that the PM structure it encapsulates is a RECTL.
  66.  
  67. Then there are the PMAnchorBlock, PMMessageQueue and PMApp classes; the
  68. first two classes contatin respectivly a HAB and a HMQ, and add some
  69. special constructors and 'dumb' inline functions that mirror PM APIs
  70. which refer to the HAB or HMQ. (For example WinGetMsg, etc.)
  71. The PMApp class is the main class for a PM++ application and contains
  72. the command line parameters, a PMAnchorBlock and a PMMessageQueue, and a
  73. few functions to process the window messages of the application's main 
  74. thread.
  75. With these classes the main() function of a PM++ application can be as
  76. simple as:
  77.  
  78.     PMApp *App;
  79.  
  80.     int main (int argc,char* argv[])
  81.     {
  82.         PMAnchorBlock ab;
  83.         PMMessageQueue mq;
  84.         ab.init();
  85.         mq.create(ab);
  86.         
  87.         App=new PMApp(ab,mq,argc,argv);
  88.     
  89.         PMWin * w=new PMWin(ab);
  90.         w->createWin();
  91.         
  92.         App->run();
  93.     
  94.         w->destroyWin();
  95.     
  96.         mq.destroy();
  97.         ab.uninit();
  98.     
  99.         return (0);
  100.     }
  101.  
  102. The PMIniProfile class eases the access to the Profile files (Prf...
  103. APIs).  
  104. The PMThread class automatically creates a new thread in the
  105. PM++ application.  Using a clever :) hack the thread procedure is a
  106. virtual member of PMThread; this makes it possible to add thread
  107. instance data by simply deriving a subclass from PMThread and adding
  108. data fields.  The main procedure of the derived class can access to
  109. those data members just as if it were a normal member of the derived
  110. class.  I added also support for the non-standard thread instance data
  111. functions supplied by the emx library, and a series of functions to
  112. change the thread's settings.
  113. The PMWindowThread is very similar to a normal thread; the only
  114. difference is that it builds automatically a PMAnchorBlock and a
  115. PMMessageQueue, simplifying the implementation of window procedure
  116. threads.
  117. The PMEvent structure encapsulates the message data normally passed to
  118. the window message procedure, plus a PCHRMSG and a PMSEMSG to ease
  119. access to the CHRMSG and MSEMSG structures passed with WM_CHAR and
  120. WM_mouse messages. The ret field is used to return a MRESULT value from
  121. message handling functions.
  122.  
  123.  
  124.  
  125.     3. Window Class Hierarchy
  126.     
  127.     The base class is obviously PMWin: this class contains some data 
  128. (a PMAnchorBlock, the window handle, the frame window handle, and a pointer
  129. to a CreateArgs structure, which is used during the window creation).
  130. The PM window is not created in the constructor: only the CreateArgs
  131. structure is filled.  The PM window is than created by a separate
  132. functions.  With this hack it is possible for derived classes to change
  133. some CreateArgs in the constructor before the window is created.  Once
  134. allocated with the new operator, a PMWin is never deleted: when a
  135. WM_DESTROY message arrives to the window message procedure, the PMWin 
  136. object is automatically deleted by the PM++ system.
  137. There are a lot of inline functions to hide the PM APIs that refer to
  138. the window handle (HWND), and some inline functions to query the
  139. internal data of the PMWin class (the HWND etc.)
  140. There is also a certain number of virtual functions for processing the 
  141. most common messages (WM_PAINT, WM_COMMAND, WM_CHAR...).  All other
  142. messages are processed in the other() function.
  143.     The PMWin object (and all derived classes) is connected to the HWND 
  144. troughall the whole system with the typical WinSet/QueryWindowPtr
  145. method, with the PMWin pointer stored in the QWP_USER position (offset 
  146. 0).  This lets the standard C  window procedure call always the message 
  147. dispacher routine of the right PMWin object, without allocating more 
  148. window instance data.
  149.  
  150. PMWin is the base class for PMMainWin, which adds some standard functions
  151. for main application window (special menu selections: file open, file
  152. new, etc., and a special version of the paint function which gets a
  153. ready-to-use referece to a PMPresSpace (the PM++ equivalent of the HPS).
  154.  
  155. The message processing virtual functions must return FALSE if they don't
  156. process the message (so that the message dispatcher will call the
  157. default PM routine), or TRUE if they do.  The return code of the message
  158. processing (MRESULT in PM jargon) can be set by the message return
  159. function trough the ret field of the PMEvent structure.
  160.  
  161. The PMSubclassWin class is a special window class that permits to create
  162. PMWindow objects for subclassed windows via the WinSubclassWindow.  The
  163. only difference from the normal PMWin is the constructor and the
  164. createWin function, while all the other parts of the PMWin class work
  165. just as usual.
  166.  
  167.  
  168.     4. The Graphics Interface
  169.      
  170.     The PMPointer class is used to access automatically the pointer 
  171. handling functions of the PM API: WinLoadPointer and WinSetPointer.  It
  172. is possible to load a pointer with the constructor and to set it as the 
  173. system pointer using the set routine.  The reset routine restores the
  174. arrow as the default pointer.
  175.  
  176. The PMMenu class load and popups menu.
  177.  
  178. The PMDeviceContext class permits to open, handle, and close Device
  179. Contexts.  This is the base class for the PMPrinterDC and PMMemoryDC
  180. classes which automatically create a DC for the default printer and a
  181. memory device context compatible to the supplied DC.  The PMPrinterDC
  182. offers also functions to call the system setup dialog for the printer,
  183. to start a document and to end it.
  184.  
  185. The PMPresSpace class encapsulates some of the Gpi...  functions and
  186. comes in various flavors: PMWindowPresSpace (a PS obtained from a Window
  187. handle, used by the paint message processing routine), and
  188. PMMicroCachedPresSpace (a m.c. PS also obtained from a Window handle.),
  189. and PMPresSpace, connected to a supplied PMDeviceContext. 
  190.  
  191. Printing is very easy with these supplied classes: a sample printout can
  192. be produced with as little code as:
  193.  
  194.     PMPrinterDC printer(hab); // create an instance of a PMPrinterDC
  195.     printer.open();             // open the DC
  196.     printer.startDoc("Test Document");
  197.  
  198.     PMPresSpace *ptr=new
  199.     PMPresSpace(&printer, 1000, 1000,
  200.         PU_ARBITRARY|PU_LOENGLISH|GPIF_DEFAULT|GPIT_NORMAL|GPIA_ASSOC, hab);
  201.  
  202.     //    [draw on ptr]
  203.  
  204.     delete ptr;
  205.     printer.endDoc("Test Document");
  206.  
  207.     
  208.  
  209.     5. The Dialog Subsystem
  210.     
  211.     The dialog handling is quite sophisticated, but very simple to use:
  212. for most dialog windows it is not necessary to write a message handling
  213. function because dialogs derived from PMModalDialog or PMModelessDialog 
  214. receive automatically from them most of the normal processing involved in
  215. dialog functions.  It is only necessary to build a table which connects
  216. each dialog control to a C++ data structure; the following is an example
  217. of a simple dialog box with two entry fields connected to two char
  218. arrays in a C++ structure (dlgsize):
  219.  
  220.     struct _dlgsize { // define and create dlgsize
  221.         char sx[10];
  222.         char sy[10];
  223.     } dlgsize;
  224.     // create table which connects each control (the DSIZE... macros
  225.     // are defined in an include file common to the .cpp and .rc sources)
  226.     // to the members of the _dlgsize structure
  227.     static PMControlMap ctrlmap[]={ 
  228.         cmEntryField(DSIZE_EF_SX,_dlgsize,sx)
  229.         cmEntryField(DSIZE_EF_SY,_dlgsize,sy)
  230.         cmEnd(DSIZE_EF_SX)   // set default active control
  231.     };
  232.     // initalize the dlgsize structure
  233.     sprintf(dlgsize.sx,"%d",100);
  234.     sprintf(dlgsize.sy,"%d",100);
  235.     // create a dialog box, using the dlgsize structure as data area for
  236.     // storing the user's inputs.
  237.     PMModalDialog sizedlg(HWND_DESKTOP,hwnd,DLG_SIZE,ctrlmap,&dlgsize);
  238.     int ret=sizedlg.createWin();
  239.     if (ret) {
  240.         // use data in dlgsize...
  241.     }
  242.  
  243. If very 'interactive' dialogs are needed you can just derive a class
  244. from one of the PMDialog... classes and add the needed functionalities.
  245. The PMDialog class (base for PMModelessDialog and PMModalDialog) is
  246. derived from the PMWin class and adds only a functions and data members 
  247. typical of dialog windows; it inherits form PMWin all standard functions
  248. (inline and virtual).
  249. The File and Font system default dialog windows are also encapsulated,
  250. and it is possible to change their behaviour just as for normal dialogs.
  251.  
  252. The dialog window keeps a list of PMControl objects which refer to the
  253. dialog controls.  PMControl is inherited from PMWin, so all inline
  254. functions are inherited form PMWin.  PMControl has also two virtual
  255. functions (get and set) which permit to get and set the control specific
  256. data in an uniform and control-independent way.
  257.  
  258.  
  259.  
  260.     6. Important notice
  261.  
  262. This library is provided AS IS with no warranty that it will meet your
  263. needs or perform as expected and with no support from my side.  
  264.  
  265.                    This is freeware software.  
  266.     
  267. You can modify or use this code as you wish, provided that my
  268. portion of the code reamins freeware (i.e. available to anyone, in
  269. source code form) and that you keep my notice at the beginning of each
  270. file.
  271.  
  272. If you discover bugs or if you want to help me in developing new
  273. versions of the library, you can contact me at:
  274.  
  275. Giovanni Iachello
  276. giac@dei.unipd.it
  277.  
  278. on the Internet or at:
  279.  
  280. Giovanni Iachello
  281. 2:333/801.13 or 2:333/300.22 
  282.  
  283. on Fidonet.
  284.  
  285.  
  286.     7. Bibliography
  287.     
  288.     "OS/2 Presentation Manager Programming", Charles Petzold, Ziff-Davis
  289. Press, 1994. ISBN 1-56276-123-4
  290.  
  291.     "The Art of OS/2 2.1 C Programming", Panov, Salomon and Panov,
  292. Wiley-Qed, 1993. ISBN 0-471-58802-4
  293.  
  294.     "Windows++", Paul DiLascia, Addison Wesley, 1992. ISBN 0-201-60891-X
  295.     
  296.     "The Hitchhikers Guide To the Galaxy", Douglas Adams
  297.     
  298.     And also other very interesting magazines and pubblications, like
  299. the EDMI/2 free electronic OS/2 programmer's magazine (kudos to Larry
  300. Salomon Jr.!), and many programming examples on the various OS/2 support
  301. sites on the internet.
  302.     
  303.     
  304.  
  305.     8. Biographical notes
  306.     
  307.     The author of this class library is me, Giovanni Iachello.  I'm 21
  308. years old and I'm a 3rd year software engeneering student at Padua
  309. University in Padua, Italy.  My hobbies include skiing, playing
  310. role-play games, listening to *good* music, programming (!) and
  311. discovering this strange world.
  312.  
  313.  
  314.  
  315.  
  316.